package com.itita.weibo.ui;


import weibo4andriod.User;
import weibo4andriod.Weibo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import com.itita.weibo.manager.IWeiboActivity;
import com.itita.weibo.manager.MainService;
import com.itita.weibo.manager.WeiboManager;
import com.itita.weibo.model.Task;
import com.itita.weibo.util.WeiboUtil;
/**
 * Logo
 * @author 焦明 2010-5-4 13:00
 *
 */
public final class LogoActivity extends Activity implements IWeiboActivity{
	
	
	//自动登录的结果
	public static final int REF_AUTO_LOGIN_RESULT = 1;
	
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        WeiboUtil.closeWindowTitleAndWindowStatusBar(this);
        this.setContentView(R.layout.logo);
        //定义splash   动画 
        final AlphaAnimation aa=new AlphaAnimation(0.4f,1.0f);
        aa.setDuration(3000);
        this.findViewById(R.id.ImageView01).startAnimation(aa);
        
        MainService.addActivity(this);
        
        aa.setAnimationListener(new AnimationListener(){

			 
			public final void onAnimationEnd(Animation arg0) {
				User user = new WeiboManager().findLoginingUser(LogoActivity.this);
				System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
	        	System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
				if(user != null){
					
					if (!com.itita.weibo.manager.MainService.isrun) {
						////System.out.println("-------启动MainService服务--------");
						MainService.isrun = true;
						Intent it = new Intent(LogoActivity.this, MainService.class);
						LogoActivity.this.startService(it);
					}
					MainService.isAutoLogin = true;
					MainService.currentUser = user;
					 
					//直接跳转到用户首页
					Intent intent=new Intent(LogoActivity.this, HomeActivity.class);
					LogoActivity.this.startActivity(intent);
					finish();
			    }
				else{
			    	//跳转到登陆页面
			    	Intent intent=new Intent(LogoActivity.this, LoginActivity.class);
					LogoActivity.this.startActivity(intent);
					finish();
			    }
			}
			 
			public  final void onAnimationRepeat(Animation arg0) {
				
			}

			 
			public  final void onAnimationStart(Animation arg0) {

			}
        	
        }
        );
    }

	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void refresh(Object... param) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initControlsAndAddControlsEvent() {
		// TODO Auto-generated method stub
		
	}
}